{
 "cells": [
  {
   "metadata": {
    "collapsed": true
   },
   "cell_type": "markdown",
   "source": [
    "#### LangChain内置的消息类型\n",
    "    SystemMessage：设定AI行为规则或背景信息，例如设定AI的初始状态、行为模式或对话的总体目标。比如作为一个代码专家，或返回json格式，通常作为输入消息序列中的第一个消息参数。\n",
    "    HumanMessage：表示来自用户输入\n",
    "    AIMessage：存储AI回复的内容，可以是文本，也可以是调用工具的请求\n",
    "    ChatMessage：可以自定义角色的通用消息类型\n",
    "    FunctionMessage/ToolMessage：函数调用/工具消息，用于函数调用结果的消息类型"
   ],
   "id": "f31600fa5cc3bbd0"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage\n",
    "import os\n",
    "\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://vip.apiyi.com/v1'\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-xU64G4hXJ4L47ko3764958119dB245D2BdEcE528767dA1Da'\n",
    "\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "system_message = SystemMessage(content=\"你是一名英语教学方面的专家\")\n",
    "human_message = HumanMessage(content=\"帮我制定一份英语六级学习计划\")\n",
    "\n",
    "messages = [system_message, human_message]\n",
    "\n",
    "response = chat_model.invoke(messages)\n",
    "print(messages)\n",
    "print(response.content)\n"
   ],
   "id": "a2242f472fb4d6d7",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
